<template>
  <div class="addDlg">
    <el-dialog :title="temp.campusId ? '编辑': '新增'" :visible.sync="dialogFormVisible" :close-on-click-modal="false"
      width="680px">
      <el-form ref="dataForm" :rules="rules" size="mini" :model="temp" label-position="right" label-width="100px"
        style="width: 500px;">
        <div class="topForm">
          <el-form-item label="目标内容：" prop="mbnr">
            <el-input id="mbnr" v-model="temp.mbnr" style="width: 480px" maxlength="32" show-word-limit />
          </el-form-item>

          <el-form-item label="替换内容：" prop="thw">
            <el-input id="thw" v-model="temp.thw" style="width: 480px" maxlength="32" show-word-limit />
          </el-form-item>

          <el-form-item label="启用状态：" prop="isHaveChildren">
            <el-switch v-model="status" />
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogFormVisible = false">
          取消
        </el-button>
        <el-button :disabled="isDisabled" size="mini" type="primary" @click="submit">
          保存
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { dictionaryApi } from '@/api/dictionary'

export default {

  data() {
    return {
      status: true,
      isDisabled: false,

      dialogFormVisible: false,
      temp: {
        id: null,
        mbnr: null,
        thw: '',
        status: 0,
      },
      rules: {
        mbnr: { required: true, message: '目标内容不能为空', trigger: 'blur' },
        thw: { required: true, message: '替换内容不能为空', trigger: 'blur' }

      }

    }
  },
  methods: {


    async showDialog(row) {

      if (row && row.id) {
        this.getDetail(row)
      } else {
        this.temp = {
          id: null,
          mbnr: null,
          thw: '',
          status: 0,
        }

        this.dialogFormVisible = true
      }
    },
    // 获取机构列表



    // 查询详情
    async getDetail(row) {
      const url = "getthlxById"
      const res = await dictionaryApi(url, {
        id: row.id
      })
      if (res.code == 200) {
        this.temp.id = res.data.id
        this.temp.mbnr = res.data.mbnr
        this.temp.thw = res.data.thw

        if (res.data.status == 1) {
          this.status = true
        } else {
          this.status = false
        }

        this.dialogFormVisible = true
      }
    },
    submit() {
      this.$refs.dataForm.validate(async valid => {
        if (valid) {
          this.isDisabled = true
          const params = {}

          params.id = this.temp.id
          params.mbnr = this.temp.mbnr
          params.thw = this.temp.thw
          params.status = this.status ? 1 : 0

          const url = "thlx"

          var res = await dictionaryApi(url, params)
          if (res.code == 200) {
            this.$message.success('操作成功！')
            this.dialogFormVisible = false
            this.$emit('getList')
          } else {
            this.$message.success(res.msg)
          }
          this.isDisabled = false
        }
      })
    }
  }

}
</script>
<style lang="scss" scoped>
.navigationcorColor {
  margin-top: 5px;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  .selectorColor {
    margin-left: 10px;
  }
}

::v-deep {
  .el-checkbox__label {
    font-size: 12px;
    color: #333;
    font-weight: normal;
  }
  // Your custom styles here
}

.addDlg {
  .topForm {
    // display: flex;
    // flex-wrap: wrap;
  }
}
</style>
